package com.yiwei.jmx.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yiwei.jmx.R;
import com.yiwei.jmx.api.model.MoneyLogModel;
import com.yiwei.jmx.util.DateTime;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class TransactionRecordAdapter extends ItemAdapter<MoneyLogModel.DataBean, TransactionRecordAdapter.DefaultHolder> {


    public TransactionRecordAdapter(Context context) {
        super(context);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_transaction_record, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        MoneyLogModel.DataBean item = getItem(position);
        if(position>0&&DateTime.toMonthUTF8Time(Long.valueOf(item.create_time) * 1000).equals(DateTime.toMonthUTF8Time(Long.valueOf(getItem(position-1).create_time) * 1000))){
            holder.txtTitle.setVisibility(View.GONE);
        }else {
            holder.txtTitle.setVisibility(View.VISIBLE);
            holder.txtTitle.setText(DateTime.toMonthUTF8Time(Long.valueOf(item.create_time) * 1000));
        }

        holder.txtTime.setText(DateTime.toDate(Long.valueOf(item.create_time) * 1000));
        holder.txtMoney.setText(item.money);
        holder.txtName.setText(item.type_name);
    }

    class DefaultHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_name)
        TextView txtName;
        @BindView(R.id.txt_time)
        TextView txtTime;
        @BindView(R.id.txt_money)
        TextView txtMoney;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onSuccess();
    }
}
